let currentPage=1;
let pageTotal=0;
let totalPage=document.getElementById("totalpage");
window.onload=function () {
    getCurrentUser();//获取第一页学生数据
    getPageTotal();//总共有多少页
}
//获取当前页用户
function getCurrentUser() {
    myAjax("get","/getCurrentUser.do","currentPage="+currentPage,showStudent,false)

}

//获取总共有多少页
function getPageTotal() {

    myAjax("get","/getPageTotal.do","",function(){
        console.log(xhr.responseText);
        pageTotal=xhr.responseText;
       totalPage.innerText=currentPage+"/"+pageTotal
    })
}

//上一页
function prevPage() {
    currentPage--;
    if(currentPage<=0){
        currentPage=1
    }else{
        totalPage.innerText=currentPage+"/"+pageTotal
        getCurrentUser()
    }

}
function nextPage() {
    currentPage++;
    if(currentPage>pageTotal){
        alert("这已经是最后一页了")
        currentPage=pageTotal;
    }else{
        totalPage.innerText=currentPage+"/"+pageTotal
        getCurrentUser();

    }

}

//博客展示函数
function showStudent() {
    //清空
    document.getElementById("userContent").innerHTML="";

    //转换数据格式
    let data=JSON.parse(xhr.responseText)

    //循环并展示数据
    for(let i=0;i<data.length;i++){
        document.getElementById("userContent").innerHTML+=`
                
                <div 
                style="
                width: 720px;
                height: 150px;
                margin-top: 10px;
                margin-left: 20px;
                border-bottom: 1px solid black;">
                
                <div
                style="
                margin-left: 20px;
                display: flex;
                justify-content: flex-start;
                align-items: center;
                "
                >
                <img style="border-radius: 50%;width: 30px;" src="./images/A7.jpg" alt="">&nbsp;
                ${data[i].username}&nbsp;</div><br/>
                <div>${data[i].pwd}</div>
                <div
                style="
                color:darkgrey;"
                >${data[i].cont}</div>
                <div><span style="color: rgb(247, 95, 95);margin-left: 600px;" >❤</span><span>123</span></div>
                </div>               
    `
    }
}
